package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.RegionQueryObject;
import cn.wolfcode.wolf2w.redis.service.IRedisService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/region")
public class MgrsiteController {

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    //列表显示
    @RequestMapping("/list")
    public String list(Model model, RegionQueryObject q){
        Page<Region> page = regionService.query(q);
        model.addAttribute("page", page);
        return "/region/list";
    }

    //添加数据
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){
        regionService.saveOrUpdate(region);
        return JsonResult.success();
    }

    //关联目的地
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        List<Destination> destinations = destinationService.selectAll();
        System.out.println(destinations);
        return destinations;

    }

    //查看区域关联的目的地
    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(String rid){
        List<Destination> list=destinationService.getDestByRegionId(rid);
        return list;
    }

    //设置热门状态
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(int hot,String id){
        regionService.changeHotValue(hot,id);
        return JsonResult.success();
    }

    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        regionService.delete(id);
        return JsonResult.success();
    }




}
